﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataAccess;
using Newtonsoft.Json;
using System.Drawing;

namespace BlueGodWeb
{
    public partial class Detail : System.Web.UI.Page
    {
        readonly bool SupportDownload = true;
        private string SrcName;
        private string SrcType;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Form["Name"] != null)
                {
                    string message = Request.Form["Name"];
                    //Response.Write(message);
                    Session["srcNameToDetails"] = message;
                }
                if (Request.Form["type"] != null)
                {
                    string message = Request.Form["type"];
                    //Response.Write(message);
                    Session["srcTypeToDetails"] = message;
                }
            }
            
            SrcName = Convert.ToString(Session["srcNameToDetails"]);
            //Session["MovieOnShow"] = SrcName;
            SrcType = Convert.ToString(Session["srcTypeToDetails"]);
            //Session["MovieOnShow"] = SrcName;

            //*******************************************************************************
            //注意，一定要将这两个量写在if判断的外面，否则每次点击按钮后变16-17行设置的默认值
            //Name=Session["MovieName"];
            //userID=Session["UserID"];
            //*******************************************************************************
            if (!IsPostBack)
            {
                Page.Header.Title = "《" + SrcName + "》 - " + Page.Header.Title;
                Name.Text = "*片　　名： 《" + SrcName + "》";

                switch (SrcType)
                {
                    default:
                    case "movie":
                        {
                            List<MOVIE> records = new DataReader().GetMovies(SrcName, null, null, null, 0, 1);
                            if (records.Count <= 0)
                            {
                                return;
                            }
                            LoadDetail(records.First());
                        }
                        break;
                    case "tv":
                        {
                            List<TV> records = new DataReader().GetTVs(SrcName, null, null, null, 0, 1);
                            if (records.Count <= 0)
                            {
                                return;
                            }
                            LoadDetail(records.First());
                        }
                        break;
                    case "cartoon":
                        {
                            List<CARTOON> records = new DataReader().GetCartoons(SrcName, null, null, null, 0, 1);
                            if (records.Count <= 0)
                            {
                                return;
                            }
                            LoadDetail(records.First());
                        }
                        break;
                    case "show":
                        {
                            List<SHOW> records = new DataReader().GetShows(SrcName, null, null, null, 0, 1);
                            if (records.Count <= 0)
                            {
                                return;
                            }
                            LoadDetail(records.First());
                        }
                        break;
                }
            }
        }

        protected void LoadDetail(MOVIE record)
        {
            FirstShowtime.Text = "*上映时间： " + record.first_showtime;

            if (record.poster_file_name.Length <= 0)
            {
                Poster.ImageUrl = "pic\\default_poster.jpg";
            }
            else
            {
                Poster.ImageUrl = "images\\MOVIE\\" + record.poster_file_name;
            }

            Director.Text = "*导　　演： " + record.director;
            Type.Text = "*类　　型： " + record.type;
            Region.Text = "*地　　区： " + record.region;
            Actor.Text = "*主　　演： " + record.actor;
            Duration.Text = "*片　　长： " + record.duration;
            Introduction.Text = record.introduction;

            if (record.screenshoot_file_name.Length <= 0)
            {
                Screenshoot.ImageUrl = "pic\\default_screenshoot.jpg";
            }
            else
            {
                Screenshoot.ImageUrl = "images\\MOVIE\\" + record.screenshoot_file_name;
            }

            if (!SupportDownload)
            {
                return;
            }
            // 下载链接
            {
                MagnetDownloadLabel.Text = "【Magnet下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、utorrent、BitComet等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.magnet_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    Magnet.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    Magnet.Controls.Add(space);
                }
            }
            {
                FTPDownloadLabel.Text = "【FTP下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、FileZilla等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.ftp_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    FTP.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    FTP.Controls.Add(space);
                }
            }
        }

        protected void LoadDetail(TV record)
        {
            FirstShowtime.Text = "*上映时间： " + record.first_showtime;

            if (record.poster_file_name.Length <= 0)
            {
                Poster.ImageUrl = "pic\\default_poster.jpg";
            }
            else
            {
                Poster.ImageUrl = "images\\TV\\" + record.poster_file_name;
            }

            Director.Text = "*导　　演： " + record.director;
            Type.Text = "*类　　型： " + record.type;
            Region.Text = "*地　　区： " + record.region;
            Actor.Text = "*主　　演： " + record.actor;
            Duration.Text = "*片　　长： " + record.duration;
            Introduction.Text = record.introduction;

            if (record.screenshoot_file_name.Length <= 0)
            {
                Screenshoot.ImageUrl = "pic\\default_screenshoot.jpg";
            }
            else
            {
                Screenshoot.ImageUrl = "images\\TV\\" + record.screenshoot_file_name;
            }

            if (!SupportDownload)
            {
                return;
            }
            // 下载链接
            {
                MagnetDownloadLabel.Text = "【Magnet下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、utorrent、BitComet等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.magnet_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    Magnet.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    Magnet.Controls.Add(space);
                }
            }
            {
                FTPDownloadLabel.Text = "【FTP下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、FileZilla等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.ftp_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    FTP.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    FTP.Controls.Add(space);
                }
            }
        }

        protected void LoadDetail(CARTOON record)
        {
            FirstShowtime.Text = "*上映时间： " + record.first_showtime;

            if (record.poster_file_name.Length <= 0)
            {
                Poster.ImageUrl = "pic\\default_poster.jpg";
            }
            else
            {
                Poster.ImageUrl = "images\\CARTOON\\" + record.poster_file_name;
            }

            Director.Text = "*导　　演： " + record.director;
            Type.Text = "*类　　型： " + record.type;
            Region.Text = "*地　　区： " + record.region;
            Actor.Text = "*主　　演： " + record.actor;
            Duration.Text = "*片　　长： " + record.duration;
            Introduction.Text = record.introduction;

            if (record.screenshoot_file_name.Length <= 0)
            {
                Screenshoot.ImageUrl = "pic\\default_screenshoot.jpg";
            }
            else
            {
                Screenshoot.ImageUrl = "images\\CARTOON\\" + record.screenshoot_file_name;
            }

            if (!SupportDownload)
            {
                return;
            }
            // 下载链接
            {
                MagnetDownloadLabel.Text = "【Magnet下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、utorrent、BitComet等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.magnet_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    Magnet.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    Magnet.Controls.Add(space);
                }
            }
            {
                FTPDownloadLabel.Text = "【FTP下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、FileZilla等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.ftp_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    FTP.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    FTP.Controls.Add(space);
                }
            }
        }

        protected void LoadDetail(SHOW record)
        {
            FirstShowtime.Text = "*上映时间： " + record.first_showtime;

            if (record.poster_file_name.Length <= 0)
            {
                Poster.ImageUrl = "pic\\default_poster.jpg";
            }
            else
            {
                Poster.ImageUrl = "images\\SHOW\\" + record.poster_file_name;
            }

            Director.Text = "*导　　演： " + record.director;
            Type.Text = "*类　　型： " + record.type;
            Region.Text = "*地　　区： " + record.region;
            Actor.Text = "*主　　演： " + record.actor;
            Duration.Text = "*片　　长： " + record.duration;
            Introduction.Text = record.introduction;

            if (record.screenshoot_file_name.Length <= 0)
            {
                Screenshoot.ImageUrl = "pic\\default_screenshoot.jpg";
            }
            else
            {
                Screenshoot.ImageUrl = "images\\SHOW\\" + record.screenshoot_file_name;
            }

            if (!SupportDownload)
            {
                return;
            }
            // 下载链接
            {
                MagnetDownloadLabel.Text = "【Magnet下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、utorrent、BitComet等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.magnet_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    Magnet.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    Magnet.Controls.Add(space);
                }
            }
            {
                FTPDownloadLabel.Text = "【FTP下载地址】鼠标右键菜单 & 复制链接地址，然后打开迅雷、FileZilla等工具下载！";
                List<SrcObj> objList = new List<SrcObj>();
                objList = (List<SrcObj>)JsonConvert.DeserializeObject(record.ftp_url, typeof(List<SrcObj>));
                foreach (SrcObj iter in objList)
                {
                    HyperLink hl = new HyperLink();
                    hl.NavigateUrl = iter.Url;
                    hl.Text = iter.Name;
                    hl.Target = "_blank";
                    hl.ForeColor = Color.FromArgb(255, 255, 255);
                    FTP.Controls.Add(hl);
                    Label space = new Label();
                    space.Text = "<br/>";
                    FTP.Controls.Add(space);
                }
            }
        }
    }
}